#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 100010;
int head, e[N], ne[N], id;

void init() {
    head = -1;
    id = 0;
}

void add_to_head(int x) {
    e[id] = x;
    ne[id] = head;
    head = id;
    id++;
}

void add(int k, int x) {
    e[id] = x;
    ne[id] = ne[k];
    ne[k] = id;;
    id++;
}

void remove(int k) {
    ne[k] = ne[ne[k]];
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int m; cin >> m;
    init();
    while (m--) {
        char op; cin >> op;
        if (op == 'H') {
            int x; cin >> x;
            add_to_head(x);
        }else if (op == 'D') {
            int k; cin >> k;
            if (!k) head = ne[head];
            remove(k - 1);
        }else if (op == 'I') {
            int k, x; cin >> k >> x;
            add(k - 1, x);
        }
    }
    for (int i = head; i != -1; i = ne[i]) cout << e[i] << " ";
    return 0;
}